import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";
import { routerMap } from "./routerMap.js";
import { useStore } from "../store";
let routes = [
  {
    path: "/",
    name: "",
    redirect: "/admin/home",
    component: () => import("../views/index/index.vue"),
    meta: {
      keepAlive: false,
    },
  },
  ...routerMap,
];
const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  let store = useStore();
  store.$patch((state) => {
    state.routerLoading = true;
    state.tabNavList = state.tabNavList.filter((x) => x.path != to.path);
    state.tabNavList.push({ ...to });
  });
  next();
});
router.afterEach((to, from) => {
  let store = useStore();
  store.$patch((state) => {
    state.routerLoading = false; //跳转路由loading
  });
});
export default router;
